package com.example.musicapi.service;

import com.example.musicapi.dao.NewsDao;
import com.example.musicapi.dao.NoticeDao;
import com.example.musicapi.entity.News;
import com.example.musicapi.entity.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeService {
    @Autowired
    private NoticeDao noticeDao;

    public Notice add(Notice s){
        return noticeDao.save(s);
    }
    public void delete(String id){
        noticeDao.deleteById(id);
    }

    public List<Notice> findAll(int page, int size){
        Pageable pageable = PageRequest.of(page, size);
        Page<Notice> userPage = noticeDao.findAll(pageable);
        return userPage.getContent();
    }

    public List<Notice> search(int page, int size,String key){
        Pageable pageable = PageRequest.of(page, size);
        Page<Notice> userPage = noticeDao.findBySearch(key,pageable);
        return userPage.getContent();
    }

    public Notice findById(String id) {
        return noticeDao.findDataById(id);
    }


}
